// 有空的 filters 时候后端会直接抛错，在这里过滤掉
const filterEmpty = (filter) => {
  function filterOnce(filter) {
    const { filters, ...restProps } = filter;
    if (!filters) return restProps;
    if (filters.length === 0) return null;
    const nextFilters = filters.filter((filter) => filterOnce(filter));
    return {
      ...restProps,
      filters: nextFilters,
    };
  }
  return filterOnce(filter);
};

export default filterEmpty;
